// ==UserScript==
// @name          西南财经大学选课系统辅助脚本
// @namespace     http://jwc.swufe.edu.cn
// @version	      v1.0
// @description   一个很有用的小脚本，调整选课系统界面并整合部分资讯和资源
// @include       http://192.168.123.9:*/*
// @include       http://192.168.123.9/*
// @include       http://10.9.10.38:*/*
// @include       http://10.9.10.38/*
// ==/UserScript==


function addJQuery(callback) {
    var script = document.createElement("script");
    script.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js");
    script.addEventListener('load', function () {
        var script = document.createElement("script");
        script.textContent = "(" + callback.toString() + ")();";
        document.body.appendChild(script);
    }, false);
    document.body.appendChild(script);
}

// the guts of this userscript
function main() {
    if ($("#RadioButtonList1_2").length > 0) {
        $("#RadioButtonList1_2").removeAttr("disabled").attr("checked", "checked");
    }
    else if ($("#xsxk_form").length > 0) {
        var trs = $("#xsxk_form #kcmcgrid tr");
        for (i = 1; i < trs.length - 1; i++) {
            var chooseState = $(trs[i]).children("td:eq(8)").text();
            if (chooseState == "未选") {
                $(trs[i]).css({ "background": "#FA5858" });
            }
            else if (chooseState == "已选") {
                $(trs[i]).css({ "background": "#2EFE2E" });
            }
        }
    }
    else if ($("#xsxjs_form").length > 0) {
        var trs = $("#xjs_table tr.tuchu");
        for (i = 0; i < trs.length; i++) {
            var teacherName = $(trs[i]).children("td:eq(1)").text();
            alert(teacherName);
        }
    }
}

// load jQuery and execute the main function
addJQuery(main);